/* Añade en la cabeza un elemento a la lista */
addHead(X, L, [X|L]).

/* Copia una lista en otra */
copy([],[]).
copy([X|L1],[X|L2]) :- copy(L1, L2).

/*
*  add_scored_rec(+R, +SCORE, +IN, +OUT) : insert the scored recommendation into the sorted list IN, and returns the ordered list OUT
*  R = 'Name'
*  SCORE = integer value
*  IN = [(R, SCORE), ...] sorted list of recommendations
*  OUT = list result of the sorted insert of (R, SCORE) into IN
*
*  test: IN = [(vaca, 23), (pans, 20), (kyoto, 8)], add_scored_rec(burger, 15, IN, OUT).
*/
add_scored_rec(R, SCORE, [], [(R, SCORE)]).

add_scored_rec(R, SCORE, [(N_I, S_I)|IN], OUT):-
    SCORE >= S_I,
    OUT = [(R, SCORE), (N_I,S_I)|IN].

add_scored_rec(R, SCORE, [(N_I, S_I)|IN], OUT):-
    SCORE < S_I,
    add_scored_rec(R, SCORE, IN, OUT1),
    OUT = [(N_I, S_I)|OUT1].